<template>
  <a-form ref="form" :model="model" :rules="form.rules" :layout="form.settings.layout"
          :label-col="form.settings.labelCol" :wrapper-col="form.settings.wrapperCol"
          :labelAlign="form.settings.labelAlign" scrollToFirstError>
    <field-render v-model:value="model[field.name]" v-for="field in form.fields" :field="field"
                  :options="options[field.datasource ? field.datasource : field.name]"/>
  </a-form>
</template>
<script>
import FieldRender from './FieldRender.vue';
import {loadOptions} from "../common/utils";

export default {
  name: "FromRender",
  components: {
    FieldRender
  },
  props: {
    model: {
      type: Object,
      required: true
    },
    form: {
      type: Object,
      required: true
    },
    options: {
      type: Object,
      required: true
    }
  },
  data() {
    return {};
  },
  methods: {
    validate() {
      return this.$refs.form.validate();
    },
    reset() {
      this.$refs.form.resetFields();
    },
    disable(name) {
      this.form.fields[name].disabled = true;
    },
    disableAll(name) {
      this.form.fields.forEach((item) => {
        item.disabled = true
      })
    },
  },
  created() {
    console.log(this.form)
  }
}
</script>

<style scoped>

</style>
